<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once './vendor/autoload.php';

use EventDispatcher\Events\DemoEvent;
use EventDispatcher\Events\TestEvent;
use EventDispatcher\Listeners\DemoListener;
use Symfony\Component\EventDispatcher\EventDispatcher;

// create dispatcher
$dispatcher = new EventDispatcher();
// create listener
$listener = new DemoListener();
// bind event by event name into listener with listener method
$dispatcher->addListener('demo.event', [$listener, 'onDemoEvent']);
// dispatch event information with name
$dispatcher->dispatch(DemoEvent::NAME, new DemoEvent());

$dispatcher->addListener('test.event', [$listener, 'onDemoEvent']);
$dispatcher->dispatch(TestEvent::NAME, new TestEvent());
